﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WMS.OutboundDetailss;
using WMS.OutboundDetailss.Dto;
using WMS.RepositoryDefinitions;
using WMS.RepositoryDefinitions.Dto;

namespace WMS.Web.Controllers
{
    public class OutboundDetailsController : Controller
    {
        private readonly IOutboundDetailsService _repository;

        public OutboundDetailsController(IOutboundDetailsService repository)
        {
            _repository = repository;
        }

        public IActionResult List()
        {
            return View();
        }

        public IActionResult Add()
        {
            return View();
        }

        public IActionResult Update(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public async Task<int> AddOutboundDetails(OutboundDetailsDto outboundDetailsDto)
        {
            var result = await _repository.AddOutboundDetails(outboundDetailsDto);
            return result;
        }

        public async Task<JsonResult> GetOutboundDetailsList(string? detailsCode, int page = 1, int limit = 10)
        {
            var result = await _repository.GetOutboundDetailsList(detailsCode, page, limit);
            return Json(new { data = result.Queryable, count = result.RowCount, code = 0 });
        }

        public async Task<int> DeleteOutboundDetails(int id)
        {
            var result = await _repository.DeleteOutboundDetails(id);
            return result;
        }

        public async Task<JsonResult> GetOutboundDetailsInfo(int id)
        {
            var list = _repository.GetOutboundDetailsInfo(id);
            return Json(new { data = list.Result });

        }

        public async Task<int> UpdateOutboundDetails(OutboundDetailsDto outboundDetailsDto)
        {
            var result = await _repository.UpdateOutboundDetails(outboundDetailsDto);
            return result;
        }
    }
}
